﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SaveTheQueen.Actions;
using SaveTheQueen.Component;
using SaveTheQueen.Utils;

namespace SaveTheQueen.Scene
{
    public abstract class BaseScene : Sprite
    {
        private SpriteEffects postProcessEffect;
        private Effect postProcessShader;

        public SpriteEffects PostProcessEffect
        {
            get { return postProcessEffect; }
            set { postProcessEffect = value; }
        }
        public Effect PostProcessShader
        {
            get { return postProcessShader; }
            set { postProcessShader = value; }
        }


        public BaseScene(Game game)
            : base(0, 0, 800, 450, null, game)
        {
            Tint = Color.Black;
            postProcessEffect = SpriteEffects.None;
            Fade(Color.Black, Color.White, 1.5f);
        }

        protected override Vector2 sourceSize()
        {
            return new Vector2(800, 450);
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public virtual void PostProcess(Texture2D target, SpriteManager sm, GameTime gameTime)
        {
            sm.Begin();
            sm.DrawSprite(target, Offset, Tint, 0f, Vector2.Zero, Vector2.One, postProcessEffect, 0f, postProcessShader, Matrix.Identity);
            sm.End();
        }

        protected void ChangeScene(BaseScene nextScene)
        {
            Vector4BlendAction ba = Fade(Color.White, Color.Black, 1f);
            ba.OnFinished += delegate()
            {
                System.Diagnostics.Debug.WriteLine("Calling Core.ChangeScene()");
                Core.ChangeScene(nextScene);
            };
            this.Actions.Add(ba);
        }
    }
}
